﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Maticsoft.DBUtility;



namespace download
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

           
            if (!IsPostBack) {
                if (Session["islogin"]!=null)
                {
                    Load();
                }
                else {
                    Response.Redirect("login.aspx");
                }
               
            }
        }

        private void Load()
        {
            int pageIndex = (this.AspNetPager1.CurrentPageIndex - 1)*this.AspNetPager1.PageSize ;
            int pageSize =  this.AspNetPager1.CurrentPageIndex * this.AspNetPager1.PageSize;


           
            string where = " 1=1 ";
            if (!txtstime.Text.ToString().Equals("") && !txtetime.Text.ToString().Equals("")) {
                where += " and time between '" + txtstime.Text.ToString() + "' and '" + txtetime.Text.ToString() + "'";
            }
            if (!txtip.Text.ToString().Equals("")) {
                where += " and ip like '%" + txtip.Text.ToString() + "%'";
            }
            string sql = "select * from(select RN=ROW_NUMBER() OVER(ORDER BY Id desc),* from download";
            sql += " where " + where + ") as a where a.RN between " + pageIndex + " and " + pageSize;
            DataTable dt = DbHelperSQL.Query(sql).Tables[0];


            int count = Convert.ToInt32(DbHelperSQL.Query("select count(*) as c  from download where " + where).Tables[0].Rows[0]["c"]);
            this.AspNetPager1.RecordCount = count;
           


            this.rpdata.DataSource = dt;
            this.rpdata.DataBind();

        
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Load();
        }

       

      

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            Load();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string sql = "delete from download";
            DbHelperSQL.ExecuteSql(sql);
            Load();
        }
    }
}